<?php
/**
 * Created by PhpStorm.
 * User: cowthan
 * Date: 2018/7/8
 * Time: 下午9:43
 */

namespace App\Http\Controllers;


use Illuminate\Http\Request;
use Think\Exception;

class CommonController extends Controller
{

    function getImageFromStorage(Request $request){
        //获取当前的url

        //echo $request->path();  //image/11.jpg
        $realpath = str_replace('image/','/app/', $request->path());

        $path = storage_path() . $realpath;

        if(!file_exists($path)){
            //报404错误
            header("HTTP/1.1 404 Not Found");
            header("Status: 404 Not Found");
            exit;
        }
        //输出图片
        $filename = basename($request->path());
        header('Content-type: image/*');
        header('Content-Disposition:attachment;filename=' . $filename);
        header('Content-Length:' . filesize($path));
        echo file_get_contents($path);

    }

}